package com.hyd.tweet.twitter;

import twitter4j.DirectMessage;
import twitter4j.User;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * (description)
 *
 * @author yiding.he
 */
public class DirectMessageFormatter {

    private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("MM/dd HH:mm");

    public static String formatDirectMessage(DirectMessage message) {
        return String.format("%s【%s(%s)】%s",
                formatDate(message.getRecipient(), message.getCreatedAt()),
                message.getSender().getName(),
                message.getSender().getScreenName(),
                message.getText());
    }

    public static String formatDate(User user, Date date) {
        int offset = user.getUtcOffset();
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.SECOND, offset);
        return SIMPLE_DATE_FORMAT.format(c.getTime());
    }
}
